home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / darkseal.c < prev    next >
C/C++ Source or Header  |  2000-04-08  |  10KB  |  381 lines

  1. /***************************************************************************
  2.  
  3.    Dark Seal Video emulation - Bryan McPhail, mish@tendril.co.uk
  4.  
  5. ****************************************************************************
  6.  
  7. Data East custom chip 55:  Generates two playfields, playfield 1 is underneath
  8. playfield 2.  Dark Seal uses two of these chips.  1 playfield is _always_ off
  9. in this game.
  10.  
  11.     16 bytes of control registers per chip.
  12.  
  13.     Word 0:
  14.         Mask 0x0080: Flip screen
  15.         Mask 0x007f: ?
  16.     Word 2:
  17.         Mask 0xffff: Playfield 2 X scroll (top playfield)
  18.     Word 4:
  19.         Mask 0xffff: Playfield 2 Y scroll (top playfield)
  20.     Word 6:
  21.         Mask 0xffff: Playfield 1 X scroll (bottom playfield)
  22.     Word 8:
  23.         Mask 0xffff: Playfield 1 Y scroll (bottom playfield)
  24.     Word 0xa:
  25.         Mask 0xc000: Playfield 1 shape??
  26.         Mask 0x3000: Playfield 1 rowscroll style (maybe mask 0x3800??)
  27.         Mask 0x0300: Playfield 1 colscroll style (maybe mask 0x0700??)?
  28.  
  29.         Mask 0x00c0: Playfield 2 shape??
  30.         Mask 0x0030: Playfield 2 rowscroll style (maybe mask 0x0038??)
  31.         Mask 0x0003: Playfield 2 colscroll style (maybe mask 0x0007??)?
  32.     Word 0xc:
  33.         Mask 0x8000: Playfield 1 is 8*8 tiles else 16*16
  34.         Mask 0x4000: Playfield 1 rowscroll enabled
  35.         Mask 0x2000: Playfield 1 colscroll enabled
  36.         Mask 0x1f00: ?
  37.  
  38.         Mask 0x0080: Playfield 2 is 8*8 tiles else 16*16
  39.         Mask 0x0040: Playfield 2 rowscroll enabled
  40.         Mask 0x0020: Playfield 2 colscroll enabled
  41.         Mask 0x001f: ?
  42.     Word 0xe:
  43.         ??
  44.  
  45. Locations 0 & 0xe are mostly unknown:
  46.  
  47.                              0        14
  48. Caveman Ninja (bottom):        0053    1100 (changes to 1111 later)
  49. Caveman Ninja (top):        0010    0081
  50. Two Crude (bottom):            0053    0000
  51. Two Crude (top):            0010    0041
  52. Dark Seal (bottom):            0010    0000
  53. Dark Seal (top):            0053    4101
  54. Tumblepop:                    0010    0000
  55. Super Burger Time:            0010    0000
  56.  
  57. Location 0xe looks like it could be a mirror of another byte..
  58.  
  59. **************************************************************************
  60.  
  61. Sprites - Data East custom chip 52
  62.  
  63.     8 bytes per sprite, unknowns bits seem unused.
  64.  
  65.     Word 0:
  66.         Mask 0x8000 - ?
  67.         Mask 0x4000 - Y flip
  68.         Mask 0x2000 - X flip
  69.         Mask 0x1000 - Sprite flash
  70.         Mask 0x0800 - ?
  71.         Mask 0x0600 - Sprite height (1x, 2x, 4x, 8x)
  72.         Mask 0x01ff - Y coordinate
  73.  
  74.     Word 2:
  75.         Mask 0xffff - Sprite number
  76.  
  77.     Word 4:
  78.         Mask 0x8000 - ?
  79.         Mask 0x4000 - Sprite is drawn beneath top 8 pens of playfield 4
  80.         Mask 0x3e00 - Colour (32 palettes, most games only use 16)
  81.         Mask 0x01ff - X coordinate
  82.  
  83.     Word 6:
  84.         Always unused.
  85.  
  86. ***************************************************************************/
  87.  
  88. #include "driver.h"
  89. #include "vidhrdw/generic.h"
  90.  
  91. unsigned char *darkseal_pf12_row,*darkseal_pf34_row;
  92. unsigned char *darkseal_pf1_data,*darkseal_pf2_data,*darkseal_pf3_data;
  93.  
  94. static unsigned char darkseal_control_0[16];
  95. static unsigned char darkseal_control_1[16];
  96.  
  97. static struct tilemap *pf1_tilemap,*pf2_tilemap,*pf3_tilemap;
  98. static unsigned char *gfx_base;
  99. static int gfx_bank,flipscreen;
  100.  
  101. /***************************************************************************/
  102.  
  103. /* Function for all 16x16 1024x1024 layers */
  104. static UINT32 darkseal_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
  105. {
  106.     /* logical (col,row) -> memory offset */
  107.     return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x20) << 5) + ((row & 0x20) << 6);
  108. }
  109.  
  110. static void get_bg_tile_info(int tile_index)
  111. {
  112.     int tile,color;
  113.  
  114.     tile=READ_WORD(&gfx_base[2*tile_index]);
  115.     color=tile >> 12;
  116.     tile=tile&0xfff;
  117.  
  118.     SET_TILE_INFO(gfx_bank,tile,color)
  119. }
  120.  
  121. static void get_fg_tile_info(int tile_index)
  122. {
  123.     int tile=READ_WORD(&darkseal_pf1_data[2*tile_index]);
  124.     int color=tile >> 12;
  125.  
  126.     tile=tile&0xfff;
  127.     SET_TILE_INFO(0,tile,color)
  128. }
  129.  
  130. /******************************************************************************/
  131.  
  132. static void update_24bitcol(int offset)
  133. {
  134.     int r,g,b;
  135.  
  136.     r = (READ_WORD(&paletteram[offset]) >> 0) & 0xff;
  137.     g = (READ_WORD(&paletteram[offset]) >> 8) & 0xff;
  138.     b = (READ_WORD(&paletteram_2[offset]) >> 0) & 0xff;
  139.  
  140.     palette_change_color(offset / 2,r,g,b);
  141. }
  142.  
  143. WRITE_HANDLER( darkseal_palette_24bit_rg_w )
  144. {
  145.     /* only 1280 out of 2048 colors are actually used */
  146.     if (offset >= 2*Machine->drv->total_colors) return;
  147.  
  148.     COMBINE_WORD_MEM(&paletteram[offset],data);
  149.     update_24bitcol(offset);
  150. }
  151.  
  152. WRITE_HANDLER( darkseal_palette_24bit_b_w )
  153. {
  154.     /* only 1280 out of 2048 colors are actually used */
  155.     if (offset >= 2*Machine->drv->total_colors) return;
  156.  
  157.     COMBINE_WORD_MEM(&paletteram_2[offset],data);
  158.     update_24bitcol(offset);
  159. }
  160.  
  161. READ_HANDLER( darkseal_palette_24bit_rg_r )
  162. {
  163.     return READ_WORD(&paletteram[offset]);
  164. }
  165.  
  166. READ_HANDLER( darkseal_palette_24bit_b_r )
  167. {
  168.     return READ_WORD(&paletteram_2[offset]);
  169. }
  170.  
  171. /******************************************************************************/
  172.  
  173. static void darkseal_mark_sprite_colours(void)
  174. {
  175.     int offs,color,i,pal_base,colmask[32];
  176.  
  177.     palette_init_used_colors();
  178.  
  179.     pal_base = Machine->drv->gfxdecodeinfo[3].color_codes_start;
  180.     for (color = 0;color < 32;color++) colmask[color] = 0;
  181.     for (offs = 0;offs < 0x800;offs += 8)
  182.     {
  183.         int x,y,sprite,multi;
  184.  
  185.         sprite = READ_WORD (&buffered_spriteram[offs+2]) & 0x1fff;
  186.         if (!sprite) continue;
  187.  
  188.         y = READ_WORD(&buffered_spriteram[offs]);
  189.         x = READ_WORD(&buffered_spriteram[offs+4]);
  190.         color = (x >> 9) &0x1f;
  191.  
  192.         x = x & 0x01ff;
  193.         if (x >= 256) x -= 512;
  194.         x = 240 - x;
  195.         if (x>256) continue; /* Speedup */
  196.  
  197.         multi = (1 << ((y & 0x0600) >> 9)) - 1;    /* 1x, 2x, 4x, 8x height */
  198.  
  199.         sprite &= ~multi;
  200.  
  201.         while (multi >= 0)
  202.         {
  203.             colmask[color] |= Machine->gfx[3]->pen_usage[sprite + multi];
  204.             multi--;
  205.         }
  206.     }
  207.  
  208.     for (color = 0;color < 32;color++)
  209.     {
  210.         for (i = 1;i < 16;i++)
  211.         {
  212.             if (colmask[color] & (1 << i))
  213.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  214.         }
  215.     }
  216.  
  217.     if (palette_recalc())
  218.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  219. }
  220.  
  221. static void darkseal_drawsprites(struct osd_bitmap *bitmap)
  222. {
  223.     int offs;
  224.  
  225.     for (offs = 0;offs < 0x800;offs += 8)
  226.     {
  227.         int x,y,sprite,colour,multi,fx,fy,inc,flash,mult;
  228.  
  229.         sprite = READ_WORD (&buffered_spriteram[offs+2]) & 0x1fff;
  230.         if (!sprite) continue;
  231.  
  232.         y = READ_WORD(&buffered_spriteram[offs]);
  233.         x = READ_WORD(&buffered_spriteram[offs+4]);
  234.  
  235.         flash=y&0x1000;
  236.         if (flash && (cpu_getcurrentframe() & 1)) continue;
  237.  
  238.         colour = (x >> 9) &0x1f;
  239.  
  240.         fx = y & 0x2000;
  241.         fy = y & 0x4000;
  242.         multi = (1 << ((y & 0x0600) >> 9)) - 1;    /* 1x, 2x, 4x, 8x height */
  243.  
  244.         x = x & 0x01ff;
  245.         y = y & 0x01ff;
  246.         if (x >= 256) x -= 512;
  247.         if (y >= 256) y -= 512;
  248.         x = 240 - x;
  249.         y = 240 - y;
  250.  
  251.         if (x>256) continue; /* Speedup */
  252.  
  253.         sprite &= ~multi;
  254.         if (fy)
  255.             inc = -1;
  256.         else
  257.         {
  258.             sprite += multi;
  259.             inc = 1;
  260.         }
  261.  
  262.         if (flipscreen)
  263.         {
  264.             y=240-y;
  265.             x=240-x;
  266.             if (fx) fx=0; else fx=1;
  267.             if (fy) fy=0; else fy=1;
  268.             mult=16;
  269.         }
  270.         else mult=-16;
  271.  
  272.         while (multi >= 0)
  273.         {
  274.             drawgfx(bitmap,Machine->gfx[3],
  275.                     sprite - multi * inc,
  276.                     colour,
  277.                     fx,fy,
  278.                     x,y + mult * multi,
  279.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  280.  
  281.             multi--;
  282.         }
  283.     }
  284. }
  285.  
  286. /******************************************************************************/
  287.  
  288. WRITE_HANDLER( darkseal_pf1_data_w )
  289. {
  290.     COMBINE_WORD_MEM(&darkseal_pf1_data[offset],data);
  291.     tilemap_mark_tile_dirty(pf1_tilemap,offset/2);
  292. }
  293.  
  294. WRITE_HANDLER( darkseal_pf2_data_w )
  295. {
  296.     COMBINE_WORD_MEM(&darkseal_pf2_data[offset],data);
  297.     tilemap_mark_tile_dirty(pf2_tilemap,offset/2);
  298. }
  299.  
  300. WRITE_HANDLER( darkseal_pf3_data_w )
  301. {
  302.     COMBINE_WORD_MEM(&darkseal_pf3_data[offset],data);
  303.     tilemap_mark_tile_dirty(pf3_tilemap,offset/2);
  304. }
  305.  
  306. WRITE_HANDLER( darkseal_pf3b_data_w ) /* Mirror */
  307. {
  308.     darkseal_pf3_data_w(offset+0x1000,data);
  309. }
  310.  
  311. WRITE_HANDLER( darkseal_control_0_w )
  312. {
  313.     COMBINE_WORD_MEM(&darkseal_control_0[offset],data);
  314. }
  315.  
  316. WRITE_HANDLER( darkseal_control_1_w )
  317. {
  318.     COMBINE_WORD_MEM(&darkseal_control_1[offset],data);
  319. }
  320.  
  321. /******************************************************************************/
  322.  
  323. int darkseal_vh_start(void)
  324. {
  325.     pf1_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,64,64);
  326.     pf2_tilemap = tilemap_create(get_bg_tile_info,darkseal_scan,    TILEMAP_TRANSPARENT,16,16,64,64);
  327.     pf3_tilemap = tilemap_create(get_bg_tile_info,darkseal_scan,    TILEMAP_OPAQUE,     16,16,64,64);
  328.  
  329.     if (!pf1_tilemap || !pf2_tilemap || !pf3_tilemap)
  330.         return 1;
  331.  
  332.     pf1_tilemap->transparent_pen = 0;
  333.     pf2_tilemap->transparent_pen = 0;
  334.  
  335.     return 0;
  336. }
  337.  
  338. /******************************************************************************/
  339.  
  340. void darkseal_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  341. {
  342.     flipscreen=!(READ_WORD(&darkseal_control_0[0])&0x80);
  343.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  344.  
  345.     /* Update scroll registers */
  346.     tilemap_set_scrollx( pf1_tilemap,0, READ_WORD(&darkseal_control_1[6]) );
  347.     tilemap_set_scrolly( pf1_tilemap,0, READ_WORD(&darkseal_control_1[8]) );
  348.     tilemap_set_scrollx( pf2_tilemap,0, READ_WORD(&darkseal_control_1[2]) );
  349.     tilemap_set_scrolly( pf2_tilemap,0, READ_WORD(&darkseal_control_1[4]) );
  350.  
  351.     if (READ_WORD(&darkseal_control_0[0xc])&0x4000) { /* Rowscroll enable */
  352.         int offs,scrollx=READ_WORD(&darkseal_control_0[6]);
  353.  
  354.         tilemap_set_scroll_rows(pf3_tilemap,512);
  355.         for (offs = 0;offs < 512;offs++)
  356.             tilemap_set_scrollx( pf3_tilemap,offs, scrollx + READ_WORD(&darkseal_pf34_row[(offs<<1)+0x80]) );
  357.     }
  358.     else {
  359.         tilemap_set_scroll_rows(pf3_tilemap,1);
  360.         tilemap_set_scrollx( pf3_tilemap,0, READ_WORD(&darkseal_control_0[6]) );
  361.     }
  362.     tilemap_set_scrolly( pf3_tilemap,0, READ_WORD(&darkseal_control_0[8]) );
  363.  
  364.     gfx_bank=1;
  365.     gfx_base=darkseal_pf2_data;
  366.     tilemap_update(pf2_tilemap);
  367.     gfx_bank=2;
  368.     gfx_base=darkseal_pf3_data;
  369.     tilemap_update(pf3_tilemap);
  370.     tilemap_update(pf1_tilemap);
  371.     darkseal_mark_sprite_colours();
  372.     tilemap_render(ALL_TILEMAPS);
  373.  
  374.     tilemap_draw(bitmap,pf3_tilemap,0);
  375.     tilemap_draw(bitmap,pf2_tilemap,0);
  376.     darkseal_drawsprites(bitmap);
  377.     tilemap_draw(bitmap,pf1_tilemap,0);
  378. }
  379.  
  380. /******************************************************************************/
  381.